package demo.practice.linklist;

import java.util.Stack;

public class Offer31 {

    public boolean validateStackSequences(int[] pushed, int[] popped) {

        int j=0;
        Stack<Integer> stack = new Stack<>();
        for (int i : pushed) {
            stack.add(i);
            while (!stack.empty()&&stack.peek()==popped[j]){
                j++;
                stack.pop();
            }
        }

        return stack.empty();

    }
}
